[% setvar title caller->eval BLOCK %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>caller-&gt;eval BLOCK</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: David Nicol &lt;<a href='mailto:perl6rfc@davidnicol.com'>perl6rfc@davidnicol.com</a>&gt;
  Date: 28 Sep 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 339
  Version: 1
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p><code>caller</code> is extended to allow complete access to the &quot;call frame&quot; of
the current subroutine call.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>Some new syntax is introduced, involving the <code>caller</code> keyword,
that allows evaluation of expressions from the point of view of the
situation from which the current method was called.  After thinking
about it for a while I think</p>
<pre>	caller-&gt;eval EXPRESSION;</pre>
<p>would work well, with the prototype and semantics of this construction being
identical to regular <code>eval</code>, except that resolution of names is done as
if the eval was happening where the call happened.</p>
<p>Neat tricks become possible by directly accessing the immediate symbol
table of the calling context.</p>
<li><a name='caller-&gt;eval and the hastily destructing return'></a>caller-&gt;eval and the hastily destructing return</li>
<p>Also, if we adopt
&lt;a href=<a href='http://www.mail-archive.com/perl6-internals@perl.org/msg01442.html' target='_blank'>www.mail-archive.com</a>&gt;
a hastily destructing <code>return</code>
&lt;/a&gt; (or even if we don't, but easier if we do) we might be able to
break out of loops in the calling context, for instance</p>
<pre>	return caller-&gt;eval{return undef} if $WeAreDone;</pre>
<p>would, in the case of <code>$WeAreDone</code> being true, make a first pass over
the expression to be returned, incrementing the reference counts therein,
in this case evaluating &quot;caller&quot; for a value, but not running its eval method,
then destroy the subroutine context (except for rescued values, which there
are none of here) and then evaluate the returned expression.</p>
<p>In this case, the returned expression is a flow control directive, which
will be followed,  returning an undefined value from the calling routine.</p>
<p>In this case, prefixing <code>caller-</code>eval&gt; with <code>return</code> might be optional.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p><code>caller</code> is altered to return a tied scalar that stringifies to
the &quot;caller's package name&quot; if defined, to match perl5.  This object
has some other methods though, in particular an &quot;eval&quot; method which
is described above.</p>
<p>we will still need to keep track of the names of lexical variables that
have been lost to packed offset optimizations, in case they get referred
to by name from within a called function.</p>
<p>If <code>caller-</code>eval&gt; contains flow control directives which take us out
of the calling context, the current context must be destroyed</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>perldoc -f caller</p>
<p>How To Implement Tail Recursion:
<a href='http://www.mail-archive.com/perl6-internals@perl.org/msg01442.html' target='_blank'>www.mail-archive.com</a></p>
</div>
